# Copyright (C) 2018 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Root BUILD file for Android GPU Inspector.

licenses(["notice"])  # Apache 2.0

exports_files(["LICENSE"])

load("@bazel_gazelle//:def.bzl", "gazelle")
load("//tools/build:rules.bzl", "copy_to", "copy_tree")

# gazelle:prefix github.com/google/gapid
# gazelle:resolve go    go    llvm/bindings/go/llvm                        @llvm//:go
# gazelle:resolve go    go    protos/perfetto/common                       //tools/build/third_party/perfetto:common_go_proto
# gazelle:resolve go    go    protos/perfetto/config                       //tools/build/third_party/perfetto:config_go_proto
# gazelle:resolve go    go    protos/perfetto/ipc                          //tools/build/third_party/perfetto:ipc_go_proto
# gazelle:resolve proto proto protos/perfetto/config/perfetto_config.proto @perfetto//:protos_perfetto_config_merged_config_protos
# gazelle:resolve proto go    protos/perfetto/config/perfetto_config.proto @gapid//tools/build/third_party/perfetto:config_go_proto
# gazelle:exclude gapic

gazelle(
    name = "gazelle",
    build_tags = [
        "analytics",
        "crashreporting",
    ],
    mode = "fix",
)

# Alias meant to be used with 'bazel run <alias> -- <arguments>'.
alias(
    name = "agi",
    actual = "//cmd/agi",
)

alias(
    name = "gapis",
    actual = "//cmd/gapis",
)

alias(
    name = "gapir",
    actual = "//cmd/gapir/cc:gapir",
)

alias(
    name = "gapit",
    actual = "//cmd/gapit",
)

alias(
    name = "apic",
    actual = "//cmd/apic",
)

alias(
    name = "enum_lookup",
    actual = "//cmd/enum_lookup",
)

alias(
    name = "smoketests",
    actual = "//cmd/smoketests",
)

# Rules to build the expected installed structure for running
filegroup(
    name = "pkg",
    srcs = [
        ":pkg-lib",
        ":pkg-root",
        ":pkg-strings",
    ] + select({
        "//tools/build:linux": [":perfetto"],
        "//tools/build:windows": [],
        "//tools/build:darwin": [],
    }),
)

filegroup(
    name = "symbols",
    srcs = [
        "//cmd/gapir/cc:gapir.sym",
    ] + select({
        "//tools/build:linux": [
            "//gapidapk/android/apk:arm64-v8a_gapir.sym",
            "//gapidapk/android/apk:armeabi-v7a_gapir.sym",
            "//gapidapk/android/apk:x86_gapir.sym",
        ],
        "//conditions:default": [],
    }),
)

# Rules to build the expected installed structure for running
filegroup(
    name = "gfxapi-ls",
    srcs = [
        ":extension-files",
        ":langsvr",
        ":vscode-jsonrpc",
        ":vscode-languageclient",
        ":vscode-languageserver-types",
    ],
)

copy_to(
    name = "extension-files",
    srcs = [
        "//gapil/langsvr/vscode",
    ],
    to = "gfxapi-ls-0.0.1",
)

copy_to(
    name = "langsvr",
    srcs = [
        "//gapil/langsvr",
    ],
    to = "gfxapi-ls-0.0.1/bin",
)

copy_tree(
    name = "vscode-languageclient",
    srcs = [
        "@vscode-languageclient//:vscode-languageclient",
    ],
    strip = "external/vscode-languageclient/package",
    to = "gfxapi-ls-0.0.1/node_modules/vscode-languageclient",
)

copy_tree(
    name = "vscode-jsonrpc",
    srcs = [
        "@vscode-jsonrpc//:vscode-jsonrpc",
    ],
    strip = "external/vscode-jsonrpc/package",
    to = "gfxapi-ls-0.0.1/node_modules/vscode-jsonrpc",
)

copy_tree(
    name = "vscode-languageserver-types",
    srcs = [
        "@vscode-languageserver-types//:vscode-languageserver-types",
    ],
    strip = "external/vscode-languageserver-types/package",
    to = "gfxapi-ls-0.0.1/node_modules/vscode-languageserver-types",
)

copy_to(
    name = "pkg-root",
    srcs = [
        "//cmd/agi",
        "//cmd/gapir/cc:gapir",
        "//cmd/gapis",
        "//cmd/gapit",
        "//tools/build:build.properties",
        "//cmd/device-info:device-info",
    ] + select({
        "//tools/build:no-android": [],
        "//conditions:default": [
            "//gapidapk/android/apk:arm64-v8a.apk",
            "//gapidapk/android/apk:armeabi-v7a.apk",
            "//gapidapk/android/apk:x86.apk",
        ],
    }),
    rename = {
        "armeabi-v7a.apk": "gapid-armeabi-v7a.apk",
        "arm64-v8a.apk": "gapid-arm64-v8a.apk",
        "x86.apk": "gapid-x86.apk",
    },
    to = "pkg",
)

copy_to(
    name = "pkg-lib",
    srcs = [
        "//core/vulkan/vk_virtual_swapchain/cc:json",
        "//core/vulkan/vk_virtual_swapchain/cc:libVkLayer_VirtualSwapchain",
        "//gapic:gapic_deploy.jar",
        "//gapii/cc:libgapii",
        "//gapii/vulkan/vk_graphics_spy/cc:json",
    ] + select({
        "@gapid//tools/build:linux": [
            "//core/vulkan/vk_api_timing_layer/cc:json",
            "//core/vulkan/vk_api_timing_layer/cc:libVkLayer_CPUTiming",
        ],
        "//conditions:default": [
        ],
    }) + select({
        "@gapid//tools/build:linux": [
            "//core/vulkan/vk_memory_tracker_layer/cc:json",
            "//core/vulkan/vk_memory_tracker_layer/cc:libVkLayer_MemoryTracker",
        ],
        "//conditions:default": [
        ],
    }),
    rename = {
        "gapic_deploy.jar": "gapic.jar",
    },
    to = "pkg/lib",
)

copy_to(
    name = "pkg-strings",
    srcs = ["//gapis/messages:stb"],
    to = "pkg/strings",
)

copy_to(
    name = "perfetto",
    srcs = [
        "@perfetto",
        "@perfetto//:traced",
        "@perfetto//:traced_probes",
    ],
    to = "pkg/perfetto",
)

test_suite(
    name = "tests-core",
    tests = [
        "//core/app/analytics:go_default_test",
        "//core/app/auth:go_default_test",
        "//core/app/benchmark:go_default_test",
        "//core/app/crash/reporting:go_default_test",
        "//core/app/flags:go_default_test",
        "//core/assert:go_default_test",
        "//core/cc:tests",
        "//core/codegen:go_default_test",
        "//core/context/keys:go_default_test",
        "//core/data:go_default_test",
        "//core/data/binary:go_default_test",
        "//core/data/compare:go_default_test",
        "//core/data/deep:go_default_test",
        "//core/data/dictionary:go_default_test",
        "//core/data/endian:go_default_test",
        "//core/data/generic:go_default_test",
        "//core/data/id:go_default_test",
        "//core/data/pack:go_default_test",
        "//core/data/slice:go_default_test",
        "//core/event/task:go_default_test",
        "//core/fault:go_default_test",
        "//core/fault/stacktrace:go_default_test",
        "//core/fault/stacktrace/crunch:go_default_test",
        "//core/git:go_default_test",
        "//core/image:go_default_test",
        "//core/langsvr:go_default_test",
        "//core/log:go_default_test",
        "//core/math/f16:go_default_test",
        "//core/math/f32:go_default_test",
        "//core/math/f64:go_default_test",
        "//core/math/interval:go_default_test",
        "//core/math/sint:go_default_test",
        "//core/memory/arena:go_default_test",
        "//core/memory/arena/cc:tests",
        "//core/memory_tracker/cc:tests",
        "//core/net:go_default_test",
        "//core/net/grpcutil:go_default_test",
        "//core/os/android/adb:go_default_test",
        "//core/os/android/binaryxml:go_default_test",
        "//core/os/android/manifest:go_default_test",
        "//core/os/device:go_default_test",
        "//core/os/device/host:go_default_test",
        "//core/os/device/remotessh:go_default_test",
        "//core/os/file:go_default_test",
        "//core/os/flock:go_default_test",
        "//core/os/shell:go_default_test",
        "//core/os/shell/stub:go_default_test",
        "//core/stream:go_default_test",
        "//core/stream/fmts:go_default_test",
        "//core/text:go_default_test",
        "//core/text/cases:go_default_test",
        "//core/text/parse:go_default_test",
    ],
)

test_suite(
    name = "tests-gapil",
    tests = [
        "//gapil/analysis:go_default_test",
        "//gapil/bapi:go_default_test",
        "//gapil/compiler:go_default_test",
        "//gapil/compiler/mangling/c:go_default_test",
        "//gapil/compiler/mangling/ia64:go_default_test",
        "//gapil/compiler/plugins/encoder/test:go_default_test",
        "//gapil/compiler/plugins/replay:go_default_test",
        "//gapil/fuzz:go_default_test",
        "//gapil/parser:go_default_test",
        "//gapil/resolver:go_default_test",
        "//gapil/runtime/cc:tests",
        "//gapil/semantic:go_default_test",
        "//gapil/template:go_default_test",
        "//gapil/validate:go_default_test",
    ],
)

test_suite(
    name = "tests-gapis-api",
    tests = [
        "//gapis/api:go_default_test",
        "//gapis/api/test:go_default_test",
        "//gapis/api/transform:go_default_test",
        "//gapis/api/transform2:go_default_test",
        "//gapis/api/vulkan:go_default_test",
    ],
)

test_suite(
    name = "tests-gapis-replay-resolve",
    tests = [
        "//gapis/replay/asm:go_default_test",
        "//gapis/replay/builder:go_default_test",
        "//gapis/replay/scheduler:go_default_test",
        "//gapis/resolve:go_default_test",
        "//gapis/resolve/dependencygraph2:go_default_test",
        "//gapis/resolve/dependencygraph2/graph_visualization:go_default_test",
    ],
)

test_suite(
    name = "tests-gapis-other",
    tests = [
        "//gapis/capture:go_default_test",
        "//gapis/memory:go_default_test",
        "//gapis/service/box:go_default_test",
        "//gapis/shadertools:go_default_test",
        "//gapis/shadertools/cc:tests",
        "//gapis/stringtable/minidown/parser:go_default_test",
        "//gapis/stringtable/minidown/scanner:go_default_test",
        "//gapis/stringtable/parser:go_default_test",
        "//gapis/vertex:go_default_test",
    ],
)

test_suite(
    name = "tests-gapir",
    tests = [
        "//gapir/cc:tests",
    ],
)

test_suite(
    name = "tests-general",
    tests = [
        "//test/integration/replay:go_default_test",
        "//test/integration/service:go_default_test",
    ],
)

test_suite(
    name = "tests",
    tests = [
        # __BEGIN_TESTS
        "//core/app/analytics:go_default_test",
        "//core/app/auth:go_default_test",
        "//core/app/benchmark:go_default_test",
        "//core/app/crash/reporting:go_default_test",
        "//core/app/flags:go_default_test",
        "//core/assert:go_default_test",
        "//core/cc:tests",
        "//core/codegen:go_default_test",
        "//core/context/keys:go_default_test",
        "//core/data:go_default_test",
        "//core/data/binary:go_default_test",
        "//core/data/compare:go_default_test",
        "//core/data/deep:go_default_test",
        "//core/data/dictionary:go_default_test",
        "//core/data/endian:go_default_test",
        "//core/data/generic:go_default_test",
        "//core/data/id:go_default_test",
        "//core/data/pack:go_default_test",
        "//core/data/slice:go_default_test",
        "//core/event/task:go_default_test",
        "//core/fault:go_default_test",
        "//core/fault/stacktrace:go_default_test",
        "//core/fault/stacktrace/crunch:go_default_test",
        "//core/git:go_default_test",
        "//core/image:go_default_test",
        "//core/langsvr:go_default_test",
        "//core/log:go_default_test",
        "//core/math/f16:go_default_test",
        "//core/math/f32:go_default_test",
        "//core/math/f64:go_default_test",
        "//core/math/interval:go_default_test",
        "//core/math/sint:go_default_test",
        "//core/memory/arena:go_default_test",
        "//core/memory/arena/cc:tests",
        "//core/memory_tracker/cc:tests",
        "//core/net:go_default_test",
        "//core/net/grpcutil:go_default_test",
        "//core/os/android/adb:go_default_test",
        "//core/os/android/binaryxml:go_default_test",
        "//core/os/android/manifest:go_default_test",
        "//core/os/device:go_default_test",
        "//core/os/device/host:go_default_test",
        "//core/os/device/remotessh:go_default_test",
        "//core/os/file:go_default_test",
        "//core/os/flock:go_default_test",
        "//core/os/shell:go_default_test",
        "//core/os/shell/stub:go_default_test",
        "//core/stream:go_default_test",
        "//core/stream/fmts:go_default_test",
        "//core/text:go_default_test",
        "//core/text/cases:go_default_test",
        "//core/text/parse:go_default_test",
        "//gapil/analysis:go_default_test",
        "//gapil/bapi:go_default_test",
        "//gapil/compiler:go_default_test",
        "//gapil/compiler/mangling/c:go_default_test",
        "//gapil/compiler/mangling/ia64:go_default_test",
        "//gapil/compiler/plugins/encoder/test:go_default_test",
        "//gapil/compiler/plugins/replay:go_default_test",
        "//gapil/fuzz:go_default_test",
        "//gapil/parser:go_default_test",
        "//gapil/resolver:go_default_test",
        "//gapil/runtime/cc:tests",
        "//gapil/semantic:go_default_test",
        "//gapil/template:go_default_test",
        "//gapil/validate:go_default_test",
        "//gapir/cc:tests",
        "//gapis/api:go_default_test",
        "//gapis/api/test:go_default_test",
        "//gapis/api/transform:go_default_test",
        "//gapis/api/transform2:go_default_test",
        "//gapis/api/vulkan:go_default_test",
        "//gapis/capture:go_default_test",
        "//gapis/memory:go_default_test",
        "//gapis/replay/asm:go_default_test",
        "//gapis/replay/builder:go_default_test",
        "//gapis/replay/scheduler:go_default_test",
        "//gapis/resolve:go_default_test",
        "//gapis/resolve/dependencygraph2:go_default_test",
        "//gapis/resolve/dependencygraph2/graph_visualization:go_default_test",
        "//gapis/service/box:go_default_test",
        "//gapis/shadertools:go_default_test",
        "//gapis/shadertools/cc:tests",
        "//gapis/stringtable/minidown/parser:go_default_test",
        "//gapis/stringtable/minidown/scanner:go_default_test",
        "//gapis/stringtable/parser:go_default_test",
        "//gapis/vertex:go_default_test",
        "//test/integration/replay:go_default_test",
        "//test/integration/service:go_default_test",
        # __END_TESTS
    ],
)
